# -*- encoding: utf-8 -*-
"""
@File    : User_register_try.py
@Time    : 2020/1/19 11:27 上午
@Author  : david wang
@Email   : 3063737@qq.com
@Software: PyCharm
"""
# 导入插件
import pandas as pd
import numpy as np
from pandas import DataFrame
import setting

# 定义文件路径
filename = setting.export_file+'User_register_try.html'
iopath = setting.resource_file+'User_order.xlsx'
outpath = setting.resource_file+'out.xlsx'

# 读取xls文件
df = pd.DataFrame(pd.read_excel(iopath, sheet_name='Sheet1'))

# 获取数据
cols = df.columns.values.tolist()  # 获取数据头信息
da0 = [str(i)[0:10] for i in pd.Series.tolist(pd.to_datetime(df[cols[0]]))]
da1 = pd.Series.tolist(df[cols[1]])
da2 = pd.Series.tolist(df[cols[2]])

# 导入柱状图-Bar
from pyecharts.charts import Bar
from pyecharts import options as opts
# 内置主题类型可查看 pyecharts.globals.ThemeType
from pyecharts.globals import ThemeType

print ('da0','\n',da0[25])
print ('da0','\n',da1[25])

bar = (
    Bar(init_opts=opts.InitOpts(theme=ThemeType.WHITE, height="800px", width="1500px"))
        .add_xaxis(da0)
        .add_yaxis(cols[2], (da2), label_opts=opts.LabelOpts(is_show=False),
                   # is_selectedFalse默认不显示某商品
                   is_selected=True,
                   markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average", name="平均值")]),
                   markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max", name="最大值"),
                                                           opts.MarkPointItem(type_="min", name="最大值"),
                                                           opts.MarkPointItem(type_="average", name="平均值"), ]))
        .add_yaxis(cols[1], (da1), label_opts=opts.LabelOpts(is_show=False),
                   markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average", name="平均值")]),
                   markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(value = da1[25],coord=[da0[25],da1[25]],name="关联支付宝"),
                                                           opts.MarkPointItem(type_="min", name="最小值"),
                                                           opts.MarkPointItem(type_="average", name="平均值"), ]))
        .set_global_opts(title_opts=opts.TitleOpts(title="遏制羊毛党计划", subtitle="注册用户量和试用用户量"),
                         # toolbox_opts工具栏显示
                         toolbox_opts=opts.ToolboxOpts(),
                         # legend_opts子项显示
                         legend_opts=opts.LegendOpts(is_show=True),
                         # 增加单位
                         yaxis_opts=opts.AxisOpts(
                             axislabel_opts=opts.LabelOpts(formatter="{value} /个")),
                         # 可以滑动的直方图控制
                         datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(orient="vertical")]
                         )
)
bar.render(filename)


import webbrowser
webbrowser.open_new_tab( 'file://'+filename)

